﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using Box.BL;
using Box.Entities;
using Microsoft.Practices.Unity;

namespace Box.Api.Controllers
{
    public class InsumoController : ApiController
    {
        [Dependency]
        public IInsumoBL insumoService { get; set; }

        public IEnumerable<Insumo> Get()
        {
            return insumoService.GetFromInsumosByCriterio("");
        }

        public IEnumerable<Insumo> Get(string criterio)
        {
            return insumoService.GetFromInsumosByCriterio(criterio);
        }

        [ResponseType(typeof(Insumo))]
        public IHttpActionResult Get(int id)
        {
            var insumo = insumoService.GetFromInsumosById(id);
            if (insumo == null)
            {
                return NotFound();
            }
            return Ok(insumo);
        }

        [ResponseType(typeof(Insumo))]
        public IHttpActionResult Post(Insumo insumo)
        {
            insumoService.AddInsumo(insumo);
            return CreatedAtRoute("DefaultApi", new { id = insumo.Id }, insumo);
        }
    }
}
